import sympy as sp
from sympy import symbols, limit, Piecewise, Eq

print("\n2. 复合函数条件不满足的反例")
# 定义函数
x = symbols('x')
u = symbols('u')
f_u = Piecewise((2, Eq(u, 2)), (1, True))  # u=2时f(u)=2，否则f(u)=1
g_x = 2  # 常值函数

# 外层函数极限
lim_f_u = limit(f_u, u, 2)

# 复合函数极限
composite = f_u.subs(u, g_x)
lim_composite = limit(composite, x, 1)  # x=1是任意点

print("内层函数g(x)=2，lim(x→1)g(x)=2")
print("外层函数f(u)在u≠2时值为1，在u=2时值为2")
print("lim(u→2)f(u)=1（因为u趋近2但不等于2时，f(u)=1）")
print(f"但复合函数lim(x→1)f(g(x)) = {lim_composite}")
print("两者不等，因为不满足g(x)≠u₀条件")